package com.demo.hbase;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

public class HbaseDemo {

	private static Connection connection;

	// 用HBaseconfiguration初始化配置信息是会自动加载当前应用的classpath下的hbase-site.xml
	private static Configuration conf;

	private static Admin admin;

	public static void init() throws IOException {
		if (conf == null) {
			conf = HBaseConfiguration.create();
			System.out.println(conf.get("hbase.master"));
			System.out.println(conf.get("hbase.zookeeper.quorum"));
			System.out.println(conf.get("hbase.zookeeper.property.clientPort"));
//			conf.set("hbase.master", "192.168.6.131");
//			conf.set("hbase.zookeeper.quorum", "192.168.6.131");
//			conf.set("hbase.zookeeper.property.clientPort", "2181");
		}
		if (connection == null) {
			connection = ConnectionFactory.createConnection(conf);
		}
		if (admin == null) {
			admin = connection.getAdmin();
		}
	}

	public static void main(String[] args) throws IOException {
		init();
	}
}
